import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useUserStore = defineStore("user", () => {
    const user = ref();
	const isLogin = computed(() => !!user.value && user.value.UserID != 0);
	
    uni.getStorage({
        key: 'user',
        success: function (res) {
            console.log("拿到数据:", res.data);
            user.value = res.data;
        }
    });

    function save() {
        uni.setStorage({
            key: 'user',
            data: user.value,
            success: function () {
                console.log('保存成功');
            }
        });
    }
	
	function logout() {
		user.value = null;
		save();
	}
    return { user, isLogin, save, logout };
});




